﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using com.cruxomatic.configuration.DTOs;
using com.cruxomatic.items.navigationstrip;

/// <summary>
/// Summary description for UrlTreeNodeItems
/// </summary>
public static partial class UrlTreeNodeItems
{
    public static UrlTreeNode Home
    {
        get { return new UrlTreeNode("Home", "/CruxHome.aspx", "Home"); }
    }

    #region Admin
    public static UrlTreeNode Admin
    {
        get
        {
            var node = new UrlTreeNode("Administration", "/Administration/Default.aspx", "Administration");
            node.AddParentNode(Home);
            return node; 
        }
    }

    #region Manage Organizations

    public static UrlTreeNode ManageOrganization
    {
        get
        {
            var node = new UrlTreeNode("Manage Companies", "/Administration/ManageCompanies.aspx", "ManageCompanies");
            node.AddParentNode(Admin);
            return node;
        }
    }

    public static UrlTreeNode ManageMyOrganization { get; set; }

    public static UrlTreeNode ManageUser { get; set; }

    public static UrlTreeNode ManageDepartment { get; set; }

    public static UrlTreeNode ManageLocation { get; set; }

    public static UrlTreeNode ManageSubLocation { get; set; }

    public static UrlTreeNode ManageUserDetail { get; set; }

    public static UrlTreeNode ResetPassword { get; set; }

    public static UrlTreeNode ChangeYourCompany
    {
        get
        {
            var node = new UrlTreeNode("Change Your Company", "/Administration/ChangeYourCompany.aspx", "ChangeYourCompany");
            node.AddParentNode(Admin);
            return node;
        }
    }

    #endregion

    #region Manage Roles

    public static UrlTreeNode ManageRole
    {
        get
        {
            var node = new UrlTreeNode("Manage Role", "/Administration/ManageRoles.aspx", "ManageRole");
            node.AddParentNode(Admin);
            return node;
        }
    }

    #endregion

    #region Assign Organizations To Users

    public static UrlTreeNode AssignCompanyToUser
    {
        get
        {
            var node = new UrlTreeNode("Assign Companies To User", "/Administration/AssignCompaniesToUser.aspx", "AssignCompanyToUser");
            node.AddParentNode(Admin);
            return node;
        }
    }

    #endregion

    #region Email Notification

    public static UrlTreeNode EmailNotification
    {
        get
        {
            var node = new UrlTreeNode("Email Notification", "/Administration/EmailNotification.aspx", "EmailNotification");
            node.AddParentNode(Admin);
            return node;
        }
    }

    #endregion
    #endregion  

    #region Methods

    public static UrlTreeNode CreateLeafUrlTreeNode(string nodeName, UrlTreeNode parent)
    {
        var node = new UrlTreeNode(nodeName, string.Empty, parent.Tag + "_" + nodeName, false);
        if (parent.Children != null) parent.Children.Clear();
        node.AddParentNode(parent);
        return node;
    }

    public static UrlTreeNode CreateNode(string nodeName, string nodeUrl, string nodeTag, UrlTreeNode parent)
    {
        var node = new UrlTreeNode(nodeName, nodeUrl, nodeTag);
        if (parent.Children != null) parent.Children.Clear();
        node.AddParentNode(parent);
        return node;
    }

    public static VistaAddressBar GetSiteNavigationControl(Page page)
    {
        var mp = page.Master;
        return mp.FindControl("VistaAddressBar1") as VistaAddressBar;
    }

    public static void SetSiteNavigation(VistaAddressBar vistaAddressBar, UrlTreeNode node)
    {
        var topNode = new UrlTreeNode();
        var tempNode = node;
        string totalTagUrl = string.Empty;
        while (tempNode.Parent != null)
        {
            topNode = tempNode;
            topNode.Children = tempNode.Children;
            totalTagUrl = "/" + topNode.Tag + totalTagUrl;
            tempNode = tempNode.Parent;
        }
        vistaAddressBar.Tree = Home;
        vistaAddressBar.Tree.AddChildNode(topNode);

        totalTagUrl = "/" + Home.Tag + totalTagUrl;
        vistaAddressBar.SetAddressByTagUrl(totalTagUrl);
    }
    #endregion
}